package com.my_musc_service.controller;

import com.my_musc_service.common.R;
import com.my_musc_service.entity.Song;
import com.my_musc_service.service.SongService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Song)表控制层
 *
 * @author makejava
 * @since 2021-06-10 20:44:49
 * @description 歌曲相关
 */
@RestController
@RequestMapping("song")
public class SongController {
    /**
     * 服务对象
     */
    @Resource
    private SongService songService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Song selectOne(Integer id) {
        return this.songService.queryById(id);
    }

    @PutMapping("update")
    public R updateSong(@RequestParam(value = "songFile", required = false) MultipartFile songFile,
                        @RequestParam(value = "lyricFile", required = false) MultipartFile lyricFile,
                        @RequestParam(value = "coverFile", required = false) MultipartFile coverFile,
                        Song song) {

        String lyricUrl = songService.updateSongInfo(songFile, lyricFile,coverFile, song);
        return R.ok().data("lyricUrl", lyricUrl);
    }

    /**
     * 删除当前歌曲
     *
     * @param song
     * @return
     */
    @DeleteMapping("delete")
    public R deleteSong(@RequestBody Song song) {
        Integer rows = songService.deleteBySong(song);
        return R.ok();
    }

    /**
     * 批量删除歌曲
     *
     * @param songList
     * @return
     */
    @DeleteMapping("deleteBatch")
    public R deleteSongBatch(@RequestBody List<Song> songList) {
        Integer rows = songService.deleteBySongList(songList);
        return R.ok();
    }
}
